package org.luxor.commons.rabbitmq.service.routing;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 水果供应商
 *
 * @author Mr.Yan  @date 2019/10/16$
 */
@Component
public class RoutingFruitReceiver {

    //水果供应商服务 接收消息
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("exchange.routing.order"),
            key = "fruit",
            value = @Queue("queue.routing.fruitOrder")
    ))
    public void fruitMsg(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag)  throws IOException {
        System.err.println("水果供应商接到订单<<< " + msg);
        // 确认消息
        channel.basicAck(deliveryTag, false);
    }

}
